$(function () {
    var pageindex = 1;//用来保存当前页码 默认为首页
    function initMovie() {//发送异步请求的函数
        $.ajax({
            "url": "/Dev_user/dev_user/getList",
            "type": "POST",
            "data": "pageIndex=" + pageindex,
            "dataType": "json",
            "success": successList
        });
    }
    function successList(data) {
        var $myTbody=$("#myTbody");
        for(var i=0;i<data.lists.length;i++){
            $myTbody.append("<tr align=\"center\">" +
                    "<td>"+data.lists[i].id+"</td>" +
                    "<td>"+data.lists[i].devCode+"</td>" +
                    "<td>"+data.lists[i].devName+"</td>"+
                    "<td>"+data.lists[i].devPassword+"</td>" +
                    "<td>"+data.lists[i].devEmail+"</td>" +
                    "<td>"+data.lists[i].devInfo+"</td>" +
                    "<td>"+data.lists[i].createdBy+"</td>" +
                    "<td>"+data.lists[i].creationDate+"</td>" +
                    "<td>"+data.lists[i].modifyBy+"</td>" +
                    "<td>"+data.lists[i].modifyDate+"</td>" +
                    "<td><a href='javascript:void(0)' class='del' value='"+data.lists[i].id+"'>删除</a>" +
                    "<a href='/Dev_user/dev_user/updDev/"+data.lists[i].id+"'>修改</a></td>" +
                    "</tr>");
            //上一页、下一页
            var $td=$("<td colspan=\"11\">当前页["+data.pageindex+"/"+data.pagecount+"]</td>");
            if(data.pageindex>1){
                $td.append("<a class=\"pageclick\" href=\"javascript:void(0)\" value=\"1\">首页</a>");
                $td.append("<a class=\"pageclick\" href=\"javascript:void(0)\" value=\""+(data.pageindex-1)+"\">上一页</a>");
            }
            if(data.pageindex<data.pagecount){
                $td.append("<a class=\"pageclick\" href=\"javascript:void(0)\" value=\""+(data.pageindex+1)+"\">下一页</a>");
                $td.append("<a class=\"pageclick\" href=\"javascript:void(0)\" value=\""+data.pagecount+"\">尾页</a>");
            }
        }
            var $tr=$("<tr align=\"center\"></tr>").append($td);
            $myTbody.append($tr);

            //点击事件
            $(".pageclick").click(function() {
                pageindex=$(this).attr("value");
                $myTbody.html("");
                initMovie();
            });
            $(".del").click(function () {
                $.get("/Dev_user/dev_user/delDev","id="+$(this).attr("value"),delDev,"text");
                function delDev(data) {
                    if (data=="true"){
                        alert("删除成功！");
                    }else{
                        alert("删除失败!");
                    }
                    $myTbody.html("");
                    initMovie();
                }

            })

    }
    initMovie();
})